<template>
<div class="field inline _myfiled" :class="{disabled: data.readonly}">
  <label :class="{must: data.is_must}">{{data.label}}</label>
  <input type="text" :maxlength="maxlength"  v-model.trim="val" @keyup.enter.stop.prevent="doNothing" :name="data.name" :placeholder="placeholder">
</div>
</template>

<script>
import tool from 'src/util/tool';
import util from '_util/index';


export default {
    data() {
      return {
        val: "",
      }
    },
    methods: {
      doNothing(event){
      }
    },
    watch: {
      data:{
        immediate: true,
        handler(val) {
        }
      },
      val(val, old){
        if(!this.data || this.data.readonly){
          return;
        }
        this.$emit("onchange", {name:this.data.name, value: val, raw: this.data})
      }
    },
    computed: {
      placeholder(){
        return this.data.placeholder || `请输入${this.data.label}`
	},
	maxlength(){
		return this.data.maxlength || ''
	}
    },
    props:{
      data:{
        type:Object,
        default(){
          return {}
        }
      },
      value:{}
    },
    created() {
      this.val = this.value;
    }
  };
</script>

<style lang="less" scoped>
  ._myfiled input{
    min-width: 300px
  }
</style>
